package com.zzyl.nursing.domain;

import com.zzyl.common.constant.HttpStatus;
import lombok.Data;

import java.io.Serializable;
@Data
public class RD <T> implements Serializable {
        private static final long serialVersionUID = 1L;

        /** 成功 */
        public static final int SUCCESS = HttpStatus.SUCCESS;

        /** 失败 */
        public static final int FAIL = HttpStatus.ERROR;

        private int code;

        private String msg;

        private T data;
        private  String operationTime;
        public static <T> RD<T> ok(T data)
        {
            return restResult(data, SUCCESS, "操作成功");
        }

        private static <T> RD<T> restResult(T data, int code, String msg)
        {
            RD apiResult=new RD();
            apiResult.setCode(code);
            apiResult.setData(data);
            apiResult.setMsg(msg);
            apiResult.setOperationTime(null);
            return apiResult;
        }

        public int getCode()
        {
            return code;
        }

        public void setCode(int code)
        {
            this.code = code;
        }

        public String getMsg()
        {
            return msg;
        }

        public void setMsg(String msg)
        {
            this.msg = msg;
        }

        public T getData()
        {
            return data;
        }

        public void setData(T data)
        {
            this.data = data;
        }

        public static <T> Boolean isError(com.zzyl.common.core.domain.R<T> ret)
        {
            return !isSuccess(ret);
        }

        public static <T> Boolean isSuccess(com.zzyl.common.core.domain.R<T> ret)
        {
            return com.zzyl.common.core.domain.R.SUCCESS == ret.getCode();
        }
    }

